export function formatter(row: any, column: any, cellValue: any, index: number) {
  if (cellValue == undefined || cellValue.length === 0) {
    return "-";
  }
  return cellValue;
}

export function formatDateFromString(row: any, column: any, cellValue: any, index: number): string {
  const date = new Date(cellValue);

  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始
  const day = String(date.getDate()).padStart(2, "0");

  const hours = String(date.getHours()).padStart(2, "0");
  const minutes = String(date.getMinutes()).padStart(2, "0");
  const seconds = String(date.getSeconds()).padStart(2, "0");

  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

export function formatPathToKey(path: string): string {
  if (!path.startsWith("/")) {
    console.error("路径格式不正确");
    return "";
  }

  // 去掉开头的 `/` 并按 `/` 拆分
  const parts = path.slice(1).split("/");
  if (parts.length < 2) {
    console.error("路径格式不符合要求");
    return "";
  }

  const section = parts[0]; // 例如 "content"
  const category = parts[1]
    .split("-") // 以 `-` 拆分
    .map((word, index) => (index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))) // 仅 `-` 后单词首字母大写
    .join(""); // 重新拼接

  return `${section}:${category}`;
}
